package tech.dongling.boot.example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.dongling.boot.anno.Component;
import tech.dongling.boot.anno.HttpProcessor;
import tech.dongling.boot.anno.ProtocolMapping;
import tech.dongling.boot.common.base.HttpBizRequest;

// HTTP业务处理器
@Component("userHttpProcessor")
@ProtocolMapping({"/user"})
public class UserHttpProcessor implements HttpProcessor {
    private static final Logger logger = LoggerFactory.getLogger(UserHttpProcessor.class);
    
    private final UserService userService;

    public UserHttpProcessor(UserService userService) {
        this.userService = userService;
    }

    @Override
    public Object handle(HttpBizRequest request) {
        logger.info("Processing user request with params: {}", request.getParams());
        
        int id = Integer.parseInt(request.getParams().get("id"));
        logger.debug("Extracted user id: {}", id);
        
        String result = userService.getUserName(id);
        logger.info("User request processed, result: {}", result);
        
        return result;
    }
}